home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / MSG Graphic Effects 1.0 Source / Hilbert wipe.c < prev    next >
Text File  |  1993-08-23  |  3KB  |  114 lines

  1. /*******************************************************************************
  2.  * Copyright © 1992-1993 Mark Pilgrim                                          *
  3.  *                                                                             *
  4.  * This file is provided as is, and may be freely distributed unaltered.  This *
  5.  * message must accompany any copy of this file.  This file may be used or     *
  6.  * modified for use for a non-commercial product provided that appropriate     *
  7.  * credit is given to the author named above.                                  *
  8.  * Commercial use of this source code is prohibited.                           *
  9.  ******************************************************************************/
  10.  
  11. #include "msg misc.h"
  12. #include "msg timing.h"
  13.  
  14. /* This fills the screen by a Hilbert space-filling curve, which is defined by
  15.    two mutually recursive drawing functions:
  16.    
  17.    X = left, Y, draw, right, X, draw, X, right, draw, Y, left
  18.    Y = right, X, draw, left, Y, draw, Y, left, draw, X, right
  19.    
  20.    Start by drawing X at the highest recursion level from the bottomleft of the
  21.    screen. (At recursion level 1, X and Y are null functions.)
  22. */
  23.  
  24. #define    RecursionLevel    4
  25. #define vBlockSize         20    /* ceiling(MAIN_WINDOW_HEIGHT / 2^RecursionLevel) */
  26. #define hBlockSize         32    /* ceiling(MAIN_WINDOW_WIDTH / 2^RecursionLevel) */
  27. #define CorrectTime 1
  28.  
  29. typedef char Hilby[11];
  30.  
  31. Hilby    HilbertPattern[]=
  32. {
  33.     {
  34.         0x02,0x69,0x00,0x01,0x42,0x00,0x42,0x01,0x00,0x69,0x02
  35.     },
  36.     {
  37.         0x01,0x42,0x00,0x02,0x69,0x00,0x69,0x02,0x00,0x42,0x01
  38.     }
  39. };
  40.  
  41. int                direction=0;
  42.  
  43. void HilbertWipe(GrafPtr, int, int, int*, int*);
  44. void HilbertWipeCall(GrafPtr);
  45.  
  46. void HilbertWipe(GrafPtr myGrafPtr, int level, int whichpattern, int* x, int* y)
  47. {
  48.     int        i;
  49.     Rect    source;
  50.     
  51.     for (i=0; i<11; i++)
  52.     {
  53.         switch (HilbertPattern[whichpattern][i])
  54.         {
  55.             case 0x01:     /* turn left */
  56.                 direction--;
  57.                 if (direction<0) direction=3;
  58.                 break;
  59.             case 0x02:     /* turn right */
  60.                 direction++;
  61.                 if (direction==4) direction=0;
  62.                 break;
  63.             case 0x00:    /* draw */
  64.                 StartTiming();
  65.                 source.top=*y-vBlockSize;
  66.                 source.bottom=*y;
  67.                 source.left=*x;
  68.                 source.right=*x+hBlockSize;
  69.                 CopyBits(&(myGrafPtr->portBits), &(gMainWindow->portBits),
  70.                                 &source, &source, 0, 0L);
  71.                 switch (direction)
  72.                 {
  73.                     case 0:
  74.                         *x+=hBlockSize;
  75.                         break;
  76.                     case 1:
  77.                         *y-=vBlockSize;
  78.                         break;
  79.                     case 2:
  80.                         *x-=hBlockSize;
  81.                         break;
  82.                     case 3:
  83.                         *y+=vBlockSize;
  84.                         break;
  85.                 }
  86.                 TimeCorrection(CorrectTime);
  87.                 break;
  88.             case 0x42:    /* call X */
  89.                 if (level>1) HilbertWipe(myGrafPtr,level-1,0,x,y);
  90.                 break;
  91.             case 0x69:    /* call Y */
  92.                 if (level>1) HilbertWipe(myGrafPtr,level-1,1,x,y);
  93.                 break;
  94.         }
  95.     }
  96. }
  97.  
  98. void HilbertWipeCall(GrafPtr myGrafPtr)
  99. {
  100.     int            curx, cury;
  101.     Rect        source;
  102.     
  103.     cury=MAIN_WINDOW_HEIGHT;
  104.     curx=0;
  105.     HilbertWipe(myGrafPtr,RecursionLevel,0,&curx,&cury);
  106.     source.bottom=MAIN_WINDOW_HEIGHT;
  107.     source.right=MAIN_WINDOW_WIDTH;
  108.     source.top=source.bottom-vBlockSize;
  109.     source.left=source.right-hBlockSize;
  110.     CopyBits(&(myGrafPtr->portBits), &(gMainWindow->portBits),
  111.                 &source, &source, 0, 0L);  /* in case we missed any bits */
  112.  
  113. }
  114.